package com.xhh.reapply.service.impl;

import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.heima.utils.thread.ThreadLocalUtil;
import com.xhh.apis.check.ICheckClient;
import com.xhh.apis.user.IUserClient;
import com.xhh.common.constants.CheckedConstants;
import com.xhh.common.constants.ScoreConstants;
import com.xhh.model.check.vos.CheckedVo;
import com.xhh.model.common.dtos.PageResponseResult;
import com.xhh.model.common.dtos.ResponseResult;
import com.xhh.model.common.enums.AppHttpCodeEnum;
import com.xhh.model.reapply.dtos.FiltrateStudentDto;
import com.xhh.model.reapply.dtos.GetRuleDto;
import com.xhh.model.reapply.pojos.Rule;
import com.xhh.model.reapply.pojos.Score;
import com.xhh.model.reapply.vos.StudentInfoVo;
import com.xhh.model.user.pojos.Student;
import com.xhh.model.user.pojos.User;
import com.xhh.reapply.mapper.RuleMapper;
import com.xhh.reapply.mapper.ScoreMapper;
import com.xhh.reapply.service.IRuleService;
import com.xhh.reapply.service.IScoreService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.HashMap;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author author
 * @since 2024-08-03
 */
@Service
@RequiredArgsConstructor
public class RuleServiceImpl extends ServiceImpl<RuleMapper, Rule> implements IRuleService {

    /**
     * 根据单位id、院系id、专业id获取调剂规则
     * @param dto
     * @return
     */
    @Override
    public ResponseResult getRuleByUCodeFCodeAndCode(GetRuleDto dto) {
        // 1. 校验参数
        if (dto.getUnityCode() == null || dto.getFaultyCode() == null || dto.getMajorCode() == null) {
            return ResponseResult.errorResult(AppHttpCodeEnum.PARAM_INVALID);
        }
        // 2. 构建查询条件
        Rule rule = lambdaQuery()
                .eq(Rule::getUnityCode, dto.getUnityCode())
                .eq(Rule::getFaultyCode, dto.getFaultyCode())
                .eq(Rule::getMajorCode, dto.getMajorCode())
                .one();
        if (rule == null) {
            return ResponseResult.errorResult(AppHttpCodeEnum.DATA_NOT_EXIST);
        }
        // 3. 返回结果
        return ResponseResult.okResult(rule);
    }
}
